package com.framework.Module.flow.flowbill;

import com.framerock.baselib.Json;
import com.framerock.baselib.Rock;
import com.framerock.db.DBWhere;
import com.framework.Flow.FlowListener;

import java.util.Map;

public class FlowListenerflowbill extends FlowListener {

    @Override
    public Boolean onModejs() {
        return true;
    }

    //首页显示待办
    public Map<String, String> onhomeData(String pnum)
    {
        if(pnum.equals("daiban")) {
            Map<String, String> da = Rock.getMap();
            da.put("total", ongetStotal(pnum)+"");//角标统计
            return da;
        }else if(Rock.isEmpt(pnum)){
            Map<String, String> da = Rock.getMap();
            da.put("data", Json.getListString(mFlow.getListData("my", "fmodeid,fmodename,fmodenum,mid,status,applydt,nowcheckname,content", 5, true)));
            da.put("zongshu", mFlow.mModel.getCount("`aid`="+mRequest.USEAID+"")+"");
            return da;
        }
        return null;
    }

    @Override
    public int ongetStotal(String pnum) {
        int to = 0;
        if(pnum.equals("daiban")){
            to = mFlow.mModel.getCount(mFlow.getFlowwhere("mydai"));
        }
        return to;
    }

    @Override
    public Boolean onisEdit() {
        return false;
    }

    @Override
    public Boolean onisDelete() {
        return false;
    }

    public void onFlowunitadd() {
        //更新为我的的申请
        mFlow.updateUnit(Rock.getMap(new String[]{
            "name","我的申请",
             "issx","1",
            "icons", "https://xinhu-1251238447.file.myqcloud.com/img/164151.png"
        }), mFlow.funitid, "");

        //判断流程待办是否存在不存在就添加
        String where= DBWhere.start()
                .winto("cid", mFlow.COMPANYID)
                .wint("modeid", mFlow.modeid)
                .wstr("url", "daiban")
                .show();
        int to = mFlow.mFlowBase.Unit().unitModel.getCount(where);
        if(to == 0){
            Map<String, String> da = mFlow.unitrs;
            da.remove("id");
            da.put("name", "流程待办");
            da.put("url", "daiban");
            da.put("issx", "1");
            mFlow.mFlowBase.Unit().unitModel.insertbo(da);
        }
    }

    @Override
    public Map<String, String> onReplacers(Map<String, String> da, int lx) {

        return da;
    }
}
